package com.ifast.common.controller;


import java.math.BigInteger;
import java.util.Arrays;

import com.ifast.common.domain.PatentinfoDO;
import com.ifast.common.service.PatentinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.AdminBaseController;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 专利信息表
 *  @author  chenwenchao
 *  @date 2018-09-18 10:42:53
 * </pre>
 * <small> 2018-09-18 10:42:53 | chenwenchao</small>
 */
@Controller
@RequestMapping("/common/patentinfo")
public class PatentinfoController extends AdminBaseController {
	@Autowired
	private PatentinfoService patentinfoService;
	
	@GetMapping()
	@RequiresPermissions("common:patentinfo:patentinfo")
	String Patentinfo(){
	    return "common/patentinfo/patentinfo";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("common:patentinfo:patentinfo")
	public Result<Page<PatentinfoDO>> list(PatentinfoDO patentinfoDTO){
        Wrapper<PatentinfoDO> wrapper = new EntityWrapper<PatentinfoDO>().orderBy("id", false);
        Page<PatentinfoDO> page = patentinfoService.selectPage(getPage(PatentinfoDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("common:patentinfo:add")
	String add(){
	    return "common/patentinfo/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("common:patentinfo:edit")
	String edit(@PathVariable("id") BigInteger id, Model model){
		PatentinfoDO patentinfo = patentinfoService.selectById(id);
		model.addAttribute("patentinfo", patentinfo);
	    return "common/patentinfo/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("common:patentinfo:add")
	public Result<String> save( PatentinfoDO patentinfo){
		patentinfoService.insert(patentinfo);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("common:patentinfo:edit")
	public Result<String>  update( PatentinfoDO patentinfo){
		boolean update = patentinfoService.updateById(patentinfo);
		return update ? Result.ok() : Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("common:patentinfo:remove")
	public Result<String>  remove( Integer id){
		patentinfoService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("common:patentinfo:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		patentinfoService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
